'use strict';

/**
 * Config for the router
 */
angular.module('app')
  .run(
    [          '$rootScope', '$state', '$stateParams','$ocLazyLoad',
      function ($rootScope,   $state,   $stateParams,$ocLazyLoad) {
          $rootScope.$state = $state;
          $rootScope.$stateParams = $stateParams;
          $ocLazyLoad.load('toaster');
      }
    ]
  )
  .config(
    [          '$stateProvider', '$urlRouterProvider',
      function ($stateProvider,   $urlRouterProvider) {
          
          $urlRouterProvider
              .otherwise('/app/news/-1/-1');
          $stateProvider
              .state('app', {
                  abstract: true,
                  url: '/app',
                  templateUrl: 'tpl/app.html'
              })
			  .state('app.news', {
                  url: '/news/{docId}/{userId}',
                  templateUrl: 'tpl/news.html',
				  resolve: {
                    deps: ['uiLoad',
                      function( uiLoad ){
                        return uiLoad.load(['js/app/news.js','vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js']);
                    }]
                  }
              })
              .state('app.records', {
                  url: '/records',
                  templateUrl: 'tpl/records.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load(['js/app/records.js']);
                          }]
                  }
              })
              .state('app.recordslist', {
                  url: '/records/{recordId:[0-9]{1,10}}',
                  templateUrl: 'tpl/records_list.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load(['js/app/records.js']);
                          }]
                  }
              })
              .state('app.recordslistdetail', {
                  url: '/records/{recordId}/{listdetailId}',
                  templateUrl: 'tpl/records_list_detail.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load(['js/app/records.js','vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js']);
                          }]
                  }
              })
              // Task
              .state('app.tasklist', {
                  url: '/tasklist',
                  templateUrl: 'tpl/task_list.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/task.js',
                                  'vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js'] );
                          }]
                  }
              })
              .state('app.taskdetail', {
                  url: '/taskdetail/{taskId:[0-9]{1,10}}',
                  templateUrl: 'tpl/task_detail.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/task.js',
                                  'vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js'] );
                          }]
                  }
              })
              //process Model
              .state('app.processmodellist', {
                  url: '/processmodellist',
                  templateUrl: 'tpl/process_model_list.html',
                  resolve: {
                      deps: ['$ocLazyLoad',

                          function( $ocLazyLoad ){
                              return $ocLazyLoad.load('angularBootstrapNavTree').then(
                                  function(){
                                      return $ocLazyLoad.load(['js/controllers/tree.js','js/app/process_model.js']);
                                  }
                              );
                          }
                      ]
                  }
              })
              .state('app.processmodeldetail', {
                  url: '/processmodeldetail/{processModelId:[0-9]{1,10}}',
                  templateUrl: 'tpl/process_model_detail.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/process_model.js'] );
                          }]
                  }
              })
              .state('app.processmodelstart', {
                  url: '/processmodelstart/{processModelId:[0-9]{1,10}}/{processParameter}',
                  templateUrl: 'tpl/process_model_start.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/process_model.js'] );
                          }]
                  }
              })
              .state('app.processmodeldashboard', {
                  url: '/processmodeldashboard/{processModelId:[0-9]{1,10}}',
                  templateUrl: 'tpl/process_model_dashboard.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/process_model.js'] );
                          }]
                  }
              })

              // process
              .state('app.processlist', {
                  url: '/processlist',
                  templateUrl: 'tpl/process_list.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/process.js',
                                  'vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js'] );
                          }]
                  }
              })
              .state('app.processdetail', {
                  url: '/processdetail/{processId:[0-9]{1,10}}',
                  templateUrl: 'tpl/process_detail.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/process.js',
                                  'vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js'] );
                          }]
                  }
              })
              .state('app.userlist', {
                  url: '/userlist/{selectGroupId}',
                  templateUrl: 'tpl/user_list.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                          function( $ocLazyLoad ){
                              return $ocLazyLoad.load('angularBootstrapNavTree').then(
                                  function(){
                                      return $ocLazyLoad.load(['js/controllers/tree.js','js/app/user.js']);
                                  }
                              );
                          }
                      ]
                  }
              })
              .state('app.userprofile', {
                  url: '/userprofile/{user}',
                  templateUrl: 'tpl/user_profile.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/user.js',
                                  'vendor/libs/moment.min.js','vendor/libs/moment-with-locales.min.js'] );
                          }]
                  }
              })
              .state('app.documentlist', {
                  url: '/documentlist/{folder}',
                  templateUrl: 'tpl/document_list.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                          function( $ocLazyLoad ){
                              return $ocLazyLoad.load('angularBootstrapNavTree').then(
                                  function(){
                                      return $ocLazyLoad.load(['js/controllers/tree.js','js/app/document.js']);
                                  }
                              );
                          }
                      ]
                  }
              })
              .state('app.page', {
                  url: '/page/{page}',
                  templateUrl: 'tpl/page.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              return uiLoad.load( ['js/app/page.js'] );
                          }]
                  }
              })
              .state('app.email', {
                  url: '/email',
                  templateUrl: 'tpl/email.html',
                  resolve: {
                  }
              })
      }
    ]
  );